"""
Case Type   : 服务端工具
Case Name   : 验证gs_check工具功能
Create At   : 2024.10.8
Owner       : wang-tianjing1
Description :
    1.CPU检查
    2.操作系统版本检查
Expect      :
    1.成功
    2.成功
History     : 
"""

import unittest
import os
from yat.test import Node
from yat.test import macro
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger




class Tools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.primary_node = Node('PrimaryDbUser')
        self.root_node = Node('PrimaryRoot')
        self.constant = Constant()

    def test_server_tools(self):
        self.log.info('-----step1:CPU检查 except:成功:-----')
        self.log.info('------------------omm用户在本地模式下检查CPU使用率-------------------')
        check_cmd2 = f'''
                               source {macro.DB_ENV_PATH};
                               gs_check -i CheckCPU -L;
                               '''
        self.log.info(check_cmd2)
        msg2 = self.primary_node.sh(check_cmd2).result()
        self.log.info(msg2)
        check_result_flag = False
        for single_msg in self.constant.GS_CHECK_SUCCESS_MSG1:
            if single_msg in msg2:
                check_result_flag = True
        self.assertTrue(check_result_flag)

        self.log.info('-----step2:操作系统版本检查 except:成功-----')
        self.log.info('------------------omm用户在本地模式下检查操作系统版本------------------')
        check_cmd2 = f'''
                                source {macro.DB_ENV_PATH}
                                gs_check -i CheckOSVer -L
                                '''
        self.log.info(check_cmd2)
        msg2 = self.primary_node.sh(check_cmd2).result()
        self.log.info(msg2)
        check_result_flag = False
        for single_msg in self.constant.GS_CHECK_SUCCESS_MSG1:
            if single_msg in msg2:
                check_result_flag = True
        self.assertTrue(check_result_flag)


    def tearDown(self):
        self.log.info('------无需清理环境-------')
        self.log.info(f'-----{os.path.basename(__file__)} end-----')